package com.leetcode.algorithm.y22.m07.w3;

/**
 * 58. 最后一个单词的长度
 * 
 * https://leetcode.cn/problems/length-of-last-word/
 * 
 * @author jie.deng
 *
 */
class Question0058Solution01 {
	
	public int lengthOfLastWord(String s) {
		int len = s.length();
		int idx = len - 1;
		while (idx >= 0 && s.charAt(idx) == ' ') {
			idx--;
		}
		int tail = idx;
		while (idx >= 0 && s.charAt(idx) != ' ') {
			idx--;
		}
		return tail - idx;
	}
    
}